package com.powergisol.gis.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.powergisol.gis.entity.TabTask;
import com.powergisol.gis.entity.TabYc;
import com.powergisol.gis.service.TabTaskService;
import com.powergisol.gis.util.Result;
import com.powergisol.gis.vo.TabTaskVo;
import com.powergisol.gis.vo.TabUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * Created By marc
 * Date: 2020/9/25  14:37
 * Description:
 */
@RestController
@RequestMapping(value = "task")
@Api(description = "任务管理" ,value = "任务管理")
public class TabTaskController extends BaseController{


    @Autowired
    private TabTaskService tabTaskService;

    @RequestMapping(value = "getTaskList", method = RequestMethod.POST)
    @ApiOperation(value = "任务列表", notes = "任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer", name = "taskState", value = "任务状态(0任务中1已完成-1任务失败)", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Integer", name = "page", value = "页数", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Date", name = "startTime", value = "时间", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Integer", name = "limit", value = "条数", defaultValue = "0", required = true, paramType = "query")
    })
    public Result getYcList(TabTaskVo vo, Principal p){
        Result result = new Result();
        TabUserVo  userVo = getUser(p);
        vo.setUserId(userVo.getId());
        PageHelper.startPage(vo.getPage(), vo.getLimit());
        PageInfo<TabTask> pageInfo = new PageInfo<>(tabTaskService.getTaskList(vo));
        result.setCount((int) pageInfo.getTotal());
        result.setData(pageInfo.getList());
        return result;
    }
}
